//全局变量
var activeId;
ajax({
    url:"http://www.antmall.cc/public/wx/collect/data/"+activeId+".html",
    success:function(data){
        var info = JSON.parse(data);
        var arr_start=info.data.active.base.startTime;
        var arr_end=info.data.active.base.endTime;
        var date_end = arr_end.replace(/-/g,"/");
        var date_start = arr_start.replace(/-/g,"/");

        function timer(){
            var ts = (new Date(date_end)) -new Date();//计算剩余的毫秒数
            var dd = parseInt(ts / 1000 / 60 / 60 / 24, 10);//计算剩余的天数   x
            var hh = parseInt(ts / 1000 / 60 / 60 % 24, 10);//计算剩余的小时数  
            var mm = parseInt(ts / 1000 / 60 % 60, 10);//计算剩余的分钟数  
            var ss = parseInt(ts / 1000 % 60, 10);//计算剩余的秒数  
            dd = checkTime(dd);  
            hh = checkTime(hh);  
            mm = checkTime(mm);  
            ss = checkTime(ss); 
            document.getElementById("day").innerHTML = dd; 
            document.getElementById("hour").innerHTML = hh;
            document.getElementById("min").innerHTML = mm;
            document.getElementById("sec").innerHTML = ss; 
            //ts-=1000;
            function checkTime(i){    
               if (i < 10) {    
                   i = "0" + i;    
                }    
               return i;    
            }
        }
        timer();
        setInterval(timer, 1000)

    }
})




function ajax(info){
    if(window.XMLHttpRequest){
        var xhr = new XMLHttpRequest(); 
    }else{
        var xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    var url = info.url;
    var type = info.type||"GET";
    var data = info.data||"";
    
    if(type=="GET"){
        xhr.open("GET",url,true);
        xhr.send();
    }else{
        xhr.open("POST",url,true);
        xhr.setRequestHeader("myHeader","myvalue");
        xhr.send(data);
    }
    
    xhr.onload = function(){
        if(info.success){
            info.success(xhr.responseText);
        }
    }
}